package com.pointbus;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.support.v7.app.ActionBarActivity;
import android.widget.LinearLayout;
import android.os.Bundle;
import com.google.android.gms.ads.*;

public class MainActivity extends ActionBarActivity {

	private GoogleMap map;
	private GPSManager gps;
	
	private AdView banner;
	
	   @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.activity_main);
	        
	        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
	        gps = new GPSManager(this);
	        
	        if(gps.canGetLocation()){
	        	//map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(gps.getLatitude(), gps.getLongitude())));
	        	map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), map.getMaxZoomLevel() - 3));
	        	
	        	MarkerOptions marker = new MarkerOptions().position(new LatLng(gps.getLatitude(), gps.getLongitude()));
	        	map.addMarker(marker);
	        }else{
	        	gps.showSettingsAlert();
	        }
	        
	        
	        banner = new AdView(this);
	        banner.setAdUnitId("ca-app-pub-1973007536197718/3425483983");
			banner.setAdSize(AdSize.BANNER);

			LinearLayout layout = (LinearLayout)findViewById(R.id.LinearLayout);
			layout.addView(banner);
			
			AdRequest requisicao = new AdRequest.Builder().build();
			banner.loadAd(requisicao);
	        
	        	        
	    }
	   
	   @Override
		  public void onPause() {
		    banner.pause();
		    super.onPause();
		  }

		  @Override
		  public void onResume() {
		    super.onResume();
		    banner.resume();
		  }

		  @Override
		  public void onDestroy() {
		    banner.destroy();
		    super.onDestroy();
		  }

}
